| Total Complexity | 3 |
| Total Lines | 19 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import {CommandHandler} from '@nestjs/cqrs'; |
||
| 9 | |||
| 10 | @CommandHandler(CreateQuoteItemsCommand) |
||
| 11 | export class CreateQuoteItemsCommandHandler { |
||
| 12 | constructor( |
||
| 13 | @Inject('IQuoteItemRepository') |
||
| 14 | private readonly quoteItemRepository: IQuoteItemRepository, |
||
| 15 | @Inject('IQuoteRepository') |
||
| 16 | private readonly quoteRepository: IQuoteRepository |
||
| 17 | ) {} |
||
| 18 | |||
| 19 | public async execute(command: CreateQuoteItemsCommand): Promise<void> { |
||
| 20 | const quote = await this.quoteRepository.find(command.quoteId); |
||
| 21 | if (!(quote instanceof Quote)) { |
||
| 22 | throw new QuoteNotFoundException(); |
||
| 23 | } |
||
| 24 | |||
| 25 | for (const {title, quantity, dailyRate, vat} of command.items) { |
||
| 26 | this.quoteItemRepository.save( |
||
| 27 | new QuoteItem(title, quantity, dailyRate, vat, quote) |
||
| 28 | ); |
||
| 32 |